var express = require('express');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

// 加载路由
var indexRouter = require('./routes/index');
var attractionsRouter = require('./routes/attractions');
var ordersRouter = require('./routes/orders');

// 初始化数据库
require('./models/database');

var app = express();

// 中间件
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

// 注册路由
app.use('/', indexRouter);
app.use('/api/attractions', attractionsRouter);
app.use('/api/orders', ordersRouter);

module.exports = app;
